<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="javax.jdo.Query" %>
<%@ page import="jp.ac.segakuen.SelectListTable" %>
<%@ page import="jp.ac.segakuen.SelectListTableUtils" %>
<%@ page import="jp.ac.segakuen.PMF" %>


<html>
<body>
<%
	String placeholder = request.getParameter("placeholder");
	PersistenceManager pm = PMF.get().getPersistenceManager();
	String query = "";

	if (placeholder == null) {
  		query = "select from jp.ac.segakuen.SelectListTable order by displayPlaceHolder asc";
 %>
 <%
	}else{
%>
	<H2>登録されている選択情報データ</H2><p>
<%
	    query = "select from jp.ac.segakuen.SelectListTable where displayPlaceHolder == '" + placeholder +"' order by sortOrder asc";
    }
	Query qr = pm.newQuery(query);
	List<SelectListTable> selectlist = (List<SelectListTable>) qr.execute();
    if (selectlist.isEmpty()) {
%>
<p>登録されているデータはありません</p>
<form action="/selectlisttableservlet" method="post">
	<p>表示データの選択 <SELECT name="placeholder">
						<OPTION value="taiken" <%if(placeholder == "taiken"){%>selected<%} %>>体験教室日程</OPTION>
						<OPTION value="examdate" <%if(placeholder == "examdate"){%>selected<%} %>>入試説明会日程</OPTION>
						<OPTION value="ocdate" <%if(placeholder == "ocdate"){ System.out.println("selected");}%>>オープンキャンパス日程</OPTION>
						<OPTION value="occourse" <%if(placeholder == "occourse"){%>selected<%} %>>オープンキャンパスコース</OPTION>
						<OPTION value="itcenter" <%if(placeholder == "itcenter"){%>selected<%} %>>社会人研修</OPTION>
					</SELECT>
	<input type="submit" name="submit" value="選択した項目を表示">
	</p>

</form>
<%
    } else {
%>
<form action="/selectlisttableservlet" method="post">
	<p>表示データの選択<SELECT name="placeholder">
						<OPTION value="taiken" <%if(placeholder == "taiken"){%>selected<%} %>>体験教室日程</OPTION>
						<OPTION value="examdate" <%if(placeholder == "examdate"){%>selected<%} %>>入試説明会日程</OPTION>
						<OPTION value="ocdate" <%if(placeholder == "ocdate"){ System.out.println("selected");}%>>オープンキャンパス日程</OPTION>
						<OPTION value="occourse" <%if(placeholder == "occourse"){%>selected<%} %>>オープンキャンパスコース</OPTION>
						<OPTION value="itcenter" <%if(placeholder == "itcenter"){%>selected<%} %>>社会人研修</OPTION>
						</SELECT>
	<input type="submit" name="submit" value="選択した項目を表示">
	</p>

</form>
<table border=4>
<TR>
<TH>表示順</TH><TH>表示内容</TH><TH>表示ページマーカー</TH><th>削除</th>
</TR>
<%
        for (SelectListTable l : selectlist) {
%>
<TR>
<td><%= l.getStringSortOrder() %></td>
<td><%= l.getListText() %></td>
<td><%= l.getDisplayPlaceHolder() %></td>
<td><form action="/selectlisttableservlet" method="post">
<input type ="hidden" name="delid" value=<%=l.getStringId()%>>
<input type="submit" name="submit" value="削除"></form></td>
</TR>
<%
        }
%>
</table>
<form action="/selectlisttableservlet" method="post">
        <input type="submit" name="submit" value="FullReset">
    	<input type="submit" name="submit" value="FullList">
</form>
<%        
    }
    pm.close();
%>
<h2>表示データの追加登録:</h2>
<form action="/selectlisttableservlet" method="post">
	<p>追加項目<SELECT name="placeholder">
						<OPTION value="taiken" <%if(placeholder == "taiken"){%>selected<%} %>>体験教室日程</OPTION>
						<OPTION value="examdate" <%if(placeholder == "examdate"){%>selected<%} %>>入試説明会日程</OPTION>
						<OPTION value="ocdate" <%if(placeholder == "ocdate"){ System.out.println("selected");}%>>オープンキャンパス日程</OPTION>
						<OPTION value="occourse" <%if(placeholder == "occourse"){%>selected<%} %>>オープンキャンパスコース</OPTION>
						<OPTION value="itcenter" <%if(placeholder == "itcenter"){%>selected<%} %>>社会人研修</OPTION>
					</SELECT>
<p>表示順（半角文字）:
	<input name="sortorder" value=""></p>
<p>表示内容（全角文字も可）:
	<input name="listtext" value=""></p>	
	<input type="submit" name="submit" value="Add">
	</p>

</form>
<h2>選択ページでデータの削除:</h2>
<form action="/selectlisttableservlet" method="post">
	<p>削除項目<SELECT name="placeholder">
						<OPTION value="taiken" <%if(placeholder == "taiken"){%>selected<%} %>>体験教室日程</OPTION>
						<OPTION value="examdate" <%if(placeholder == "examdate"){%>selected<%} %>>入試説明会日程</OPTION>
						<OPTION value="ocdate" <%if(placeholder == "ocdate"){ System.out.println("selected");}%>>オープンキャンパス日程</OPTION>
						<OPTION value="occourse" <%if(placeholder == "occourse"){%>selected<%} %>>オープンキャンパスコース</OPTION>
						<OPTION value="itcenter" <%if(placeholder == "itcenter"){%>selected<%} %>>社会人研修</OPTION>
					</SELECT>

    <p>	<input type="submit" name="submit" value="PartialReset">

    </p>
</form>
</body>
</html>
